package com.yunfei.procedure;

import oracle.jdbc.OracleTypes;

import java.sql.*;

/**
* @Description: 合同签订状态
* @Author: zhengyunfei
* @Date: 2019/2/15
* @time:16:44
*/
public class GetHeTongQianDingStatusProcedure {
    private Connection conn;
    private CallableStatement stat;
    private ResultSet rs;
    String procedureSql = "call get_crm_con_sts(?,?)";

    /**
    * @Description: 存储过程，填完理财目标的时候出发此存储过程
    * @Param: [url, driverName, username, password, userId]
    * @return: int 0成功其他失败
    * @Author: zhengyunfei
    * @Date: 2018/4/24
    * @time:13:49
    */
    public String callProcedure(String url,String driverName,String username,String password,String reserveno) {
        String result="";
        try {
            Class.forName(driverName);
            conn = DriverManager.getConnection(url, username, password);
            stat = conn.prepareCall(procedureSql);
            // 一个输入参数和三个输出参数
            stat.setString(1, reserveno);
            stat.registerOutParameter(2, OracleTypes.VARCHAR);
            stat.execute();
            result= stat.getString(2);//输出结果，如果是0代表成功
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            close(conn, stat, rs);
        }
        return result;
    }

    // 关闭连接
    public void close(Connection conn, CallableStatement stat, ResultSet rs) {
        if (rs != null) {
            try {
                rs.close();
            } catch (SQLException e) {
                e.printStackTrace();
            } finally {
                rs = null;
            }
        }
        if (stat != null) {
            try {
                stat.close();
            } catch (SQLException e) {
                e.printStackTrace();
            } finally {
                stat = null;
            }
        }
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            } finally {
                conn = null;
            }
        }
    }

    public static void main(String[] args) {
       // new GetTouZiZheRenZhengInfoProcedure().callProcedure("20180417132146779447466");
    }
}